package com.jc.oms.controller.port.in;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.jc.common.util.ExceptionUtil;
import com.jc.framework.enums.Conclusion;
import com.jc.framework.enums.LogType;
import com.jc.framework.web.ResponseBaseModel;
import com.jc.oms.controller.BaseController;
import com.jc.service.api.Api;
import com.jc.service.api.ParamModel;
import com.jc.service.systemloglist.SystemLogListService;

@Controller
@RequestMapping("api")
public class ApiController extends BaseController {
	
	@Autowired
	private Api api;
	@Autowired SystemLogListService systemLogListService;
	
	
	@RequestMapping(method = RequestMethod.POST , consumes = "application/json;charset=utf8")
	public @ResponseBody ResponseEntity<?> proess(@RequestBody ParamModel paramObject){
		
		try {
			ResponseEntity<?> ret = api.deal(paramObject);
			systemLogListService.addSystemLog(JSONObject.toJSONString(paramObject), Conclusion.OK, null, LogType.RECEIVE_H5_ORDER, JSONObject.toJSONString(ret));
			return ret;
		}catch (Exception e) {
			ResponseEntity<?> ret = new ResponseEntity<>(new ResponseBaseModel(29001,e.getMessage()), HttpStatus.OK);
			systemLogListService.addSystemLog(JSONObject.toJSONString(paramObject), Conclusion.FAIL, ExceptionUtil.subExceptionMessage(e, 0, 150), LogType.RECEIVE_H5_ORDER, JSONObject.toJSONString(ret));
			return ret;
		}
	}
	
	
	
	
	

}
